import os
from typing import Tuple, Union

def list_files(path, extentions=None):

    filepaths = []
    for root, _, files in os.walk(path):
        for file in files:
            if extentions is None:
                filepaths.append(os.path.join(root, file))
            else:
                for ext in extentions:
                    if file.endswith(ext):
                        filepaths.append(os.path.join(root, file))
    
    return filepaths

def list_files_generator(path: str, extensions: Union[None, Tuple[str]]=None):

    for root, _, files in os.walk(path):
        for file in files:
            if extensions is None:
                yield os.path.join(root, file)
            else:
                for ext in extensions:
                    if file.endswith(ext):
                        yield os.path.join(root, file)


if __name__ == '__main__':
    # filepaths = list_files(r'/home/coin/mine/project/pytutorial', ('.py',))
    # [print(file) for file in filepaths]
    for filepath in list_files_generator('/home/coin/mine/project/pytutorial/python_basics', ('.py', )):
        print(filepath)